<?php
/**
 * Created by PhpStorm.
 * User: liandne
 * Date: 2016/12/12
 * Time: 上午11:13
 */
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Builder;

/**
 * App\Doctors
 *
 * @property integer $id 标识
 * @property string $doc_name 医生名称
 * @property string $subject 主治科目
 * @property string $sexual 性别(0:女 1:男)
 * @property integer $doc_img 医生大头照
 * @property string $station 所在岗位等级
 * @property integer $bespoke_count 预约数
 * @property integer $sort 医生排序
 * @property integer $is_work 是否工作 (0:否 1:是)
 * @property string $deleted_at
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Orders[] $bespoke
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\DocHug[] $hug
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereDocName($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereSubject($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereSexual($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereDocImg($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereStation($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereBespokeCount($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereSort($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereIsWork($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereDeletedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property string $introduction 医生简介
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereIntroduction($value)
 * @property float $fee 预约价格
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereFee($value)
 * @property int $diploma_id 证书id
 * @property int $hospital_id 医院id
 * @property string $notice 医生公告
 * @property float $fee_face 面诊费用
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereDiplomaId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereFeeFace($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereHospitalId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereNotice($value)
 * @property int $user_id userid
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereUserId($value)
 * @property int $appoint_num 预约最大人数
 * @property int $face_num 面诊最大人数
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereAppointNum($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereFaceNum($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors like($field, $keyword)
 * @property string $all_amount 总收入
 * @property string $has_amount 剩余金额
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereAllAmount($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereHasAmount($value)
 * @property int $qrcode_id 推广二维码
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereQrcodeId($value)
 * @property int $dep_id 科室id
 * @method static \Illuminate\Database\Query\Builder|\App\Doctors whereDepId($value)
 */
class Doctors extends Model {

    protected $table = 'doctors';
    use SoftDeletes;

    /**
     * 用户订单表关联
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function bespoke()
    {
        return $this->hasMany('App\Orders', 'doctor_id');
    }

    /**
     * 休息表关联
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function hug(){
        return $this->hasMany('App\DocHug','doc_id');
    }

    /**
     * 课程搜索
     * @param Builder $query
     * @param         $field
     * @param         $keyword
     *
     * @return $this
     */
    public function scopeLike(Builder $query, $field, $keyword){
        return $query->where($field, 'like', '%'.$keyword.'%');
    }
}
